package com.dmall.algorithm.chapter01;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Leetcode1V1 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int minus = target - nums[i];
            if (map.containsKey(minus)) {
                return new int[] {map.get(minus), i};
            }
            map.put(nums[i], i);
        }
        return null;
    }

    public static void main(String[] args) {
        int[] nums = {3, 3};
        Leetcode1V1 leetcode1 = new Leetcode1V1();
        int[] res = leetcode1.twoSum(nums, 6);
        System.out.println(Arrays.toString(res));
    }
}
